package com.sicau.socialpracticesystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sicau.socialpracticesystem.entity.param.pointsitem.PointItemQueryParam;
import com.sicau.socialpracticesystem.entity.po.PointsItem;
import com.sicau.socialpracticesystem.mapper.PointsItemMapper;
import com.sicau.socialpracticesystem.service.PointsItemService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 积分项表 服务实现类
 * </p>
 *
 * @author sxt && ttxxi
 * @since 2021-04-26
 */
@Service
public class PointsItemServiceImpl extends ServiceImpl<PointsItemMapper, PointsItem> implements PointsItemService {

    @Resource
    PointsItemMapper pointsItemMapper;

    @Override
    public List<PointsItem> queryAllByUserNumber(Integer userNumber) {
        if (userNumber == null){
            return null;
        }
        LambdaQueryWrapper<PointsItem> queryWrapper = new LambdaQueryWrapper<PointsItem>()
                .eq(PointsItem::getUserNumber, userNumber)
                .orderByDesc(PointsItem::getId);
        return pointsItemMapper.selectList(queryWrapper);
    }

    @Override
    public IPage<PointsItem> queryByPage(PointItemQueryParam pointItemQueryParam) {
        Page<PointsItem> page = new Page<>(pointItemQueryParam.getCurrentPage(), pointItemQueryParam.getPageSize());
        LambdaQueryWrapper<PointsItem> queryWrapper = new LambdaQueryWrapper<PointsItem>()
                .eq(PointsItem::getUserNumber, pointItemQueryParam.getUserNumber())
                .orderByDesc(PointsItem::getId);
        return pointsItemMapper.selectPage(page, queryWrapper);
    }
}
